package com.afu.job;

import java.time.LocalDateTime;
import java.util.Timer;
import java.util.TimerTask;
/**
 * ClassName: JobDemo
 * Package: com.afu.job
 * Description:
 * 定时任务实现：
 * 方式一：Timer 和 TimerTask
 * Timer类允许您安排一个或多个任务在指定时间之后执行，而TimerTask类则表示要执行的任务。
 *
 * @Author zxf
 * @Create 2024/2/18 10:55
 * @Version 1.0
 */

public class JobDemo extends TimerTask {

    int times = 0;
    @Override
    public void run() {
        System.out.println("次数" +times + "时间："+ LocalDateTime.now().toString());
        times++;
    }

    public static void main(String[] args) {
        Timer timer = new Timer();
        JobDemo jobDemo = new JobDemo();
        timer.schedule(jobDemo,3000,1000);
    }
}
